<?php

/**
 * @todo 碎片管理后台 
 */
class BlockAction extends AdminAction {

    public function add() {
        $this->assign('type', 'add');
        $this->display('edit');
    }

    public function doAdd() {
        if (!$_POST['post'] || !$_POST['info']['content']) {
            $this->error('缺少必要参数');
        }
        //格式化数据
        $_POST['content'] = $_POST['info']['content'];
        $res = M('Block')->add($_POST);
        if ($res) {
            $this->success('添加广告成功');
        } else {
            $this->error('添加广告失败');
        }
    }

    public function doEdit() {
        if (!$_POST['title'] || !$_POST['info']['content']) {
            $this->error('缺少广告位标题或者广告内容');
        }
        //格式化数据
        $_POST['content'] = $_POST['info']['content'];
        $_POST['title']   = $_POST['title'];
        $res = M('Block')->save($_POST);
        if ($res >= 0) {
            $this->success('修改广告成功');
        } else {
            $this->error('修改广告失败');
        }
    }

    public function del() {
        if (empty($_POST['ids'])) {
            echo 0;
            exit;
        }
        $map = array();
        $map['id'] = array('in', t($_POST['ids']));
        echo M('Block')->where($map)->delete() ? '1' : '0';
    }

}

?>
